<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="日志日期" prop="dateTime">
        <el-date-picker clearable v-model="queryParams.dateTime" type="daterange" value-format="yyyy-MM-dd"
          range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目状态" prop="status">
        <el-select multiple v-model="queryParams.status" placeholder="请选择项目状态" clearable>
          <el-option v-for="dict in dict.type.biz_check_result" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" align="center" prop="index" />
      <el-table-column label="公司名称/项目名称" align="center" prop="name"></el-table-column>
      <el-table-column label="安全日志数量" align="center" prop="count" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="goView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>
<script>
import { getPreMonthDate } from "@/utils"
import { getStatList } from "./api"
// import RefreshMixin from "@/common/refreshMixin.js"
export default {
  name: "LogStat",
  dicts: ["biz_check_result"],
  // mixins: [RefreshMixin],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dateTime: [],
        status: [],
      },
      loading: false,
      list: [],
      total: 0,
    }
  },
  created() {
    const now = new Date();
    const date1 = this.parseTime(now, '{y}-{m}-{d}');
    const date2 = getPreMonthDate(date1)
    this.queryParams.dateTime = [date2, date1];
    this.getList();
  },
  methods: {
    async getList() {
      this.loading = true;
      const res = await getStatList({
        securityDate: this.queryParams.dateTime,
        projectStatus: this.queryParams.status,
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
      });
      this.list = res.rows.map((item, index)=> ({
        ...item,
        index: index + 1
      }));
      this.total = res.total;
      this.loading = false;
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    goView(row) {
      this.$router.push({ name: "LogStatProject", query: { id: row.projectId } })
    },
  }
}
</script>
<style lang="scss" scoped></style>